/**
 * 
 */
package sorting;

import utils.CreateUtils;
import utils.PrintUtils;

/**
 * @author Michael
 *
 */
public class BubbleSort {

	public static int[] sort(int[] a) {
		if (a == null)
			return null;
		boolean goon = true;
		for (int size = a.length - 1; size >= 0 && goon; size--) {
			goon = false;
			for (int i = 0; i < size; i++) {
				if (a[i] > a[i + 1]) {
					int tmp = a[i];
					a[i] = a[i + 1];
					a[i + 1] = tmp;
					goon = true;
				}
			}
		}
		return a;
	}
	
	/**
	 * 
	 */
	public BubbleSort() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int[] a = CreateUtils.randNonNegIntArray(50, 50);
		PrintUtils.printArray(a);
		PrintUtils.printArray(sort(a));

	}
}
